package com.baidu.model;

import java.util.UUID;

import com.jfinal.plugin.activerecord.Model;

/**
 * 云次数统计
 * @author libs
 * 2015-11-26 15:14
 */
public class CloudCount extends Model<CloudCount>{
	
	private static final long serialVersionUID = 1L;
	public static final CloudCount dao = new CloudCount();
	
	/**
	 * 获取云签到次数.经验
	 * @param code
	 * @param count
	 * @param exp
	 * @return
	 */
	public CloudCount findCountByType(Integer code, Long count, Long exp) {
		CloudCount cc = findFirst("select * from cloud_count where type =?", code);
		if(cc != null){
			cc.set("count", cc.getLong("count") + count);
			cc.set("exp", cc.getLong("exp") + exp);
			cc.update();
			return cc;
		}else{
			CloudCount bean = new CloudCount();
			bean.set("guid", UUID.randomUUID().toString());
			bean.set("type", code);
			bean.set("count", count);
			bean.set("exp", exp);
			bean.save();
			return bean;
		}
	}
	
}
